class CurModel {
    static get_client() {
        return CurModel.getItem("client");
    }

    static set_client(db) {
        sessionStorage.setItem("client", db);
    }

    static get_db(tab) {
        return CurModel.getItem(`mestab__${tab}`);
    }

    static set_db(tab, db) {
        sessionStorage.setItem(`mestab__${tab}`, db);
    }

    static get_cur_wsn() {
        return CurModel.getItem("cur_wsn", "");
    }

    static set_cur_wsn(v) {
        sessionStorage.setItem('cur_wsn', v);
    }

    static getLine() {
        const line = CurModel.getItem("line", "1");
        return line;
    }

    static setLine(cur) {
        sessionStorage.setItem('line', cur);
    }

    static setLineDes(cur) {
        sessionStorage.setItem('linedes', cur);
    }

    static getLineDes() {
        const line = CurModel.getItem("linedes", "");
        return line;
    }

    static getSelect(def) {
        return CurModel.getItem("select", def);
    }

    static setSelect(cur) {
        sessionStorage.setItem('select', cur);
    }

    static setItem(item, def) {
        sessionStorage.setItem(item, def);
    }

    static getItem(item, def) {
        let cur = sessionStorage.getItem(item);
        if (!cur) {
            return def;
        }

        if (cur.length <= 0) {
            return def;
        }

        return cur;
    }
}

class User {
    static addUser(user) {
        sessionStorage.setItem('name', user.name);
        sessionStorage.setItem('login', user.login);
        sessionStorage.setItem('auth', user.auth);
        sessionStorage.setItem('userid', user.uid);
    }

    static userId() {
        return sessionStorage.getItem('userid');
    }

    static userAuth() {
        return sessionStorage.getItem('auth');
    }

    static userName() {
        return sessionStorage.getItem('name');
    }

    static LogOut() {
        sessionStorage.setItem('login', false);
    }

    static isLogin() {
        let v = sessionStorage.getItem('login');
        return v === "true";
    }

    static isAdmin() {
        let name = sessionStorage.getItem('name');
        return name === "admin";
    }
};

const cline = () => CurModel.getLine();

export {cline, CurModel, User};
